const state = {
  typePage: {},
  typeList: [],
  list: [],
  page: {},
}

const actions = {
  saveTypes: ({ commit }, payload) => {
    commit('SAVETYPES', payload)
  },
  saveList: ({ commit }, payload) => {
    commit('SAVELIST', payload)
  },
}

const mutations = {
  SAVETYPES: (state, payload) => {
    state.typeList = payload.result
    state.typePage = {
      number: payload.number,
      total: payload.resultNum,
      size: 10
    }
  },
  SAVELIST: (state, payload) => {
    if (payload.result.length === 0) {
      state.list = []
    } else {
      state.list = payload.result.map(item => {
          return {
              id: item.id,
              publicAt: item.public_at,
              name: item.name,
              content: item.content,
              orgId: item.org_id,
              typeId: item.type_id,
              author: item.author,
              state: item.state,
              clickTimes: item.click_times,
              summary: item.summary,
              imgUrl: item.img_url,
              clickTimes: item.click_times
          }
      })
  }
    state.page = {
      number: payload.number,
      total: payload.resultNum,
      size: 10
    }
  },
}

export default {
  state,
  actions,
  mutations
}